
# include "dfxInputPlugin.h"
# include "dfxLog.h"

namespace DFX
{
    InputPlugin::InputPlugin(const String &dllFile)
        : Plugin("Core"),
        mDllFile(dllFile),
        mCreateKeyboard(NULL)
    {
    }

    InputPlugin::~InputPlugin()
    {
        Unload();
    }

    DFXRESULT InputPlugin::CreateKeyboard(Window *w, Keyboard **k)
    {
        if (mCreateKeyboard)
            return mCreateKeyboard(w, k);

        return DFX_ERROR0;
    }

    DFXRESULT InputPlugin::Load()
    {
        LoadDLL(mDllFile, (void*)&mHandle);

        if (mHandle)
        {
            mCreateKeyboard = (CREATEKEYBOARD)GetFunction("CreateKeyboard", (void*)&mHandle);
            return DFX_SUCCESS;
        }

        return DFX_ERROR0;
    }

    DFXRESULT InputPlugin::Unload()
    {
        if (mHandle)
            UnloadDLL((void*)&mHandle);

        return DFX_SUCCESS;
    }
}